package cn.ac.siom.query.action;

import cn.ac.siom.query.service.IItem_infoService;
import cn.ac.siom.query.service.ITab_ThesisService;
import cn.ac.siom.query.util.action.DefaultAction;
import cn.ac.siom.query.vo.Tab_Thesis;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping(value = "/home/*")
public class Tab_ThesisAction extends DefaultAction {
    @Resource
    private ITab_ThesisService tab_ThesisService;


    @RequestMapping(value = "tab_Thesis_Books")
    public void tab_Thesis_Books_list(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try {
            super.printObjectToList(response, "allTab_Thesis_Books", this.tab_ThesisService.list());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }



    @RequestMapping(value = "tab_Thesis_Report")
    public void tab_Thesis_Reportlist(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try {
            super.printObjectToList(response, "allTab_Thesis_Report", this.tab_ThesisService.list_Report());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping(value = "tab_Thesis_Journal")
    public void tab_Thesis_Journal_list(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");

        try {
            super.printObjectToList(response, "allTab_Thesis_Journal", this.tab_ThesisService.list_Journal());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping(value = "tab_Thesis_Conference")
    public void tab_Thesis_Conference_list(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try {
            super.printObjectToList(response, "allTab_Thesis_Conference", this.tab_ThesisService.list_Conference());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @ResponseBody
    @RequestMapping(value="findNO", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public List<Tab_Thesis> findNO(Integer i_id) throws SQLException {
        System.out.println(i_id);
        List<Tab_Thesis>  tab_Thesis = (List<Tab_Thesis>) this.tab_ThesisService.list_NO(i_id);
        for(Tab_Thesis tab_Thes:tab_Thesis) {
            System.out.println(tab_Thes.toString());
        }
        return tab_Thesis;
    }

    @ResponseBody
    @RequestMapping(value="findSearch", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public List<Tab_Thesis> findSearch(String keywords) throws SQLException {
        System.out.println(keywords);
        List<Tab_Thesis>  tab_Thesis = (List<Tab_Thesis>) this.tab_ThesisService.list_Search(keywords);
        for(Tab_Thesis tab_Thes:tab_Thesis) {
            System.out.println(tab_Thes.toString());
        }
        return tab_Thesis;
    }

    @Override
    public String getText() {
        return null;
    }
}
